package com.titaniue.java;

import java.io.Serializable;

/**
 *@program: JavaSenior
 *@description:
 *
 * Persion需要满足如下要，求方可序列化
 *
 * 1.需要实现接口：Serializable
 * 2.需要当前类提供一个全局常量：serialVersionUID
 * 3.除了当前Person类需要实现Serializable接口外，还必须保证其内存所有属性
 * 也必须是可序列化的。（默认情况下，基本数据类型可序列化）
 *
 * 补充： ObjectOutputStream和ObjectInputStream不能序列化static和transient修
 * 饰的成员变量
 *
 *@author: renfei.huange
 *@create: 2021-10-18 10:36
 */
public class Person implements Serializable {

     //序列版本号
     public static final long serialVersionUID = 47894583784532L;


    private  String name;
    private int age;
    private int id;
    private  Account account;

    public Person() {
    }

    public Person(String name, int age, Account account) {
        this.name = name;
        this.age = age;
        this.account = account;
    }

    public Person(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }


    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                ", account=" + account +
                '}';
    }
}

class  Account implements Serializable{


    public static final long serialVersionUID = 473243424221532L;

    private  double balance;

    public Account() {
    }

    public Account(double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "balance=" + balance +
                '}';
    }
}
